Creating Effective Visualizations
The Task
In this blog post we will explore and understand malaria with three informative visualizations. The malaria data came from this github: https://github.com/rfordatascience/tidytuesday/tree/master/data/2018/2018-11-13.
import plotly.io as pio
pio.renderers.default='notebook_connected'
# Inject the missing require.js dependency.
from IPython.display import display, HTML
js = '<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" integrity="sha512-c3Nl8+7g4LMSTdrm621y7kf9v3SDPnhxLNhcjFJbKECVnmZHTdo+IRO05sNLTH/D3vA6u1X32ehoLC7WFVdheg==" crossorigin="anonymous"></script>'
display(HTML(js))
import pandas as pd
import plotly.express as px
from IPython.display import HTML
import pandas as pd
import plotly
import plotly.express as px
from IPython.display import display_html, HTML
from io import StringIO
df_inc = pd.read_csv('malaria_inc.csv')
df_deaths = pd.read_csv('malaria_deaths.csv')
df_deaths_age = pd.read_csv('malaria_deaths_age.csv')
#Make df for values within income vars
income_set = ['Early-demographic dividend','Low & middle income','Low income','Lower middle income','Middle income','Upper Middle Income']
df_inc_only = df_inc[df_inc['Entity'].isin(income_set)]
Malaria Cases By Country
This first visualization shows how many cases of malaria are occurring per 1,000 people in countries around the world from 2000 - 2015. We see that the countries with the most cases of malaria are concentrated in Africa, South America, and Southeast Asia. Especially in Africa, almost all countries are experiencing 12 cases per 1,000 population. We also notice that some countries have reduced their case numbers from 2000 to 2015.
fig = px.choropleth(df_inc, locations='Code', color='Incidence of malaria (per 1,000 population at risk) (per 1,000 population at risk)',
color_continuous_scale="blues",
range_color=(0, 12),
scope="world",
labels={'Incidence of malaria (per 1,000 population at risk) (per 1,000 population at risk)':'Cases per 1,000'},
title="Malaria Cases By Country",
animation_frame="Year"
)
fig.update_geos(projection_type="natural earth")
#HTML(fig.to_html(include_plotlyjs='cdn'))
#fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
#fig.show()
#HTML(fig.to_html(include_plotlyjs='cdn'))
HTML(fig.to_html())
df_inc.head()
Malaria Deaths by Country
In this second visualization we look at how many malaria deaths are occuring in each country. The metric changes to deaths per 100,000 people. We see that most malaria deaths are concentrated in the African continent and some small parts of Southeast Asia. Many African countries are experiencing 12 deaths per 100,000 people.
fig = px.choropleth(df_deaths, locations='Code', color='Deaths - Malaria - Sex: Both - Age: Age-standardized (Rate) (per 100,000 people)',
color_continuous_scale="blues",
range_color=(0, 12),
scope="world",
labels={'Deaths - Malaria - Sex: Both - Age: Age-standardized (Rate) (per 100,000 people)':'Deaths per 100,000'},
title="Malaria Deaths By Country"
)
#fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.update_geos(projection_type="natural earth")
#fig.show()
#HTML(fig.to_html(include_plotlyjs='cdn'))
HTML(fig.to_html())
Malaria Deaths in Africa 1990-2016
In this third visualization we look at malaria deaths in African countries from 1990 - 2016. Because the malaria cases and deaths were both concentrated in African countries, this visualizations explores African countries across individual years. We see that malaria deaths worsened in the late 90's and early 2000's for the continent.
fig = px.choropleth(df_deaths, locations='Code', color='Deaths - Malaria - Sex: Both - Age: Age-standardized (Rate) (per 100,000 people)',
color_continuous_scale="blues",
range_color=(0, 12),
scope="africa",animation_frame="Year",
labels={'Deaths - Malaria - Sex: Both - Age: Age-standardized (Rate) (per 100,000 people)':'Deaths per 100,000'},
title="Malaria Deaths in Africa 1990-2016"
)
#fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig["layout"].pop("updatemenus") # optional, drop animation buttons
#fig.show()
#HTML(fig.to_html(include_plotlyjs='cdn'))
HTML(fig.to_html())